<!-- 购买标书 -->
<template>
    <div class="supply container-content">
        <div class="app-view-box">
            <el-row>
                <el-col :span="24">
                    <h1 class="panel-title">购买标书</h1>
                </el-col>
            </el-row>
            <el-row justify="end" class="export-container">
                <el-button
                    type="primary"
                    icon="el-icon-plus"
                    size="mini"
                    @click="add"
                    >新增</el-button
                >
                <el-button
                    type="primary"
                    icon="el-icon-download"
                    size="mini"
                    @click="exporting"
                    >导出</el-button
                >
            </el-row>

            <el-table
                ref="customerTable"
                :data="tableData"
                stripe
                style="width: 100%"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center">
                </el-table-column>
                <el-table-column prop="id" label="id"></el-table-column>
                <el-table-column
                    prop="bidId"
                    label="已审批通过的标书记录"
                ></el-table-column>

                <el-table-column
                    prop="buyTime"
                    label="具体购买时间"
                ></el-table-column>
                <el-table-column
                    prop="winBidCompany"
                    label="中标单位"
                ></el-table-column>
                <el-table-column
                    prop="changeTime"
                    label="更新时间"
                ></el-table-column>
                <el-table-column
                    prop="createTime"
                    label="新增时间"
                ></el-table-column>
                <el-table-column prop="tenderId" label="投标基础信息Id">
                </el-table-column>
                <el-table-column
                    prop="userId"
                    label="添加用户Id"
                ></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-tooltip
                            class="item"
                            effect="dark"
                            content="详情"
                            placement="bottom"
                        >
                            <el-button
                                plain
                                icon="el-icon-more"
                                size="mini"
                                @click="handleDetail(scope.$index, scope.row)"
                            ></el-button>
                        </el-tooltip>
                        <el-tooltip
                            class="item"
                            effect="dark"
                            content="编辑"
                            placement="bottom"
                        >
                            <el-button
                                type="primary"
                                plain
                                icon="el-icon-edit"
                                size="mini"
                                @click="handleEdit(scope.$index, scope.row)"
                            ></el-button>
                        </el-tooltip>
                        <el-tooltip
                            class="item"
                            effect="dark"
                            content="删除"
                            placement="bottom"
                        >
                            <el-button
                                type="danger"
                                plain
                                size="mini"
                                icon="el-icon-delete"
                                @click="handleDelete(scope.$index, scope.row)"
                            ></el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <el-pagination
            class="table-pagination"
            style="margin-top: 10px"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
        >
        </el-pagination>
        <el-drawer
        title="购买标书详情"
        size="100%"
        :visible.sync="drawer"
        direction="ttb"
        :before-close="handleClose">
        <detail :rowId="rowId"/>
        </el-drawer>
    </div>
</template>
<script>
import { getTenderBuyList, deleteTenderBuy,getDetailBuyList } from "@/api/system/tender";
import detail from './detail'
export default {
    components:{detail},
    data() {
        return {
            tableData: [],
            searchValue: "",
            total: 0,
            selectRows: [],
            limit: 10,
            page: 1,
            drawer:false,
            rowId:''
        };
    },
    watch: {
        "$store.state.workflow.businessDrawer": {
            handler(val) {
                if (!val) {
                    this.getData();
                }
            },
        },
    },
    methods: {
        // 获取列表
        getData() {
            getTenderBuyList({
                page: this.page,
                limit: this.limit,
            }).then((res) => {
                this.tableData = res.data.records;
                this.total = res.data.total;
            });
        },
        //新增客户
        add() {
            this.$store.dispatch("workflow/getModel", {
                menuId: this.$route.meta.menuId,
                type: "launch",
            });
        },
        //客户详情
        handleDetail(index, row) {
            this.drawer = true
            this.rowId = row.id
        },
        // 编辑客户
        handleEdit(index, row) {
            getDetailBuyList(row.id).then((res) => {
                this.$store.dispatch("workflow/getModel", {
                menuId: this.$route.meta.menuId,
                type: "edit",
                formData:res.data
            });
            });
        },
        handleClose(done){
            this.$confirm('确定要离开吗？')
        .then(_ => {
          done()
        })
        .catch(_ => {});
        },

        // 删除item
        handleDelete(index, row) {
            this.$confirm("请确定要删除所选的记录吗？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    deleteTenderBuy(row.id).then((res) => {
                        if (res.code === 200) {
                            this.tableData.splice(index, 1);
                            this.$message({
                                type: "success",
                                message: "删除成功!",
                            });
                            this.getData();
                        }
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除",
                    });
                });
        },
        // 导出按钮
        exporting() {
            console.log("exporting");
        },
        // 表格checkcbox事件
        handleSelectionChange(rows) {
            this.selectRows = rows;
        },
        //分页器size
        handleSizeChange(val) {
            this.limit = val;
            this.getData();
        },
        //分页器page
        handleCurrentChange(val) {
            this.page = val;
            this.getData();
        },
    },

    created() {
        this.getData();
    },
};
</script>
<style lang="scss" scoped>
// .visits {
//   padding: 15px;
// }
.pagination {
    margin-top: 10px;
}

.filter-container {
    margin-bottom: 15px;
}

.export-container {
    margin: 15px 0;
}

.panel-title {
    font-size: 18px;
    color: #37474f;
    font-weight: 500;
    text-shadow: rgba(0, 0, 0, 0.15) 0 0 1px;
}

.divider {
    margin: 0;
}
</style>
